$(document).ready(function () {
    getIframeSrc('waitIndex.html');
    // 渲染左侧导航列表
    $ajax('post', 'http://' + window.location.host + '/wsyypt/admin/menu', '', 'json', function (data) {
        var i, DIV_before, DIV_a, DIV_ul_before, hole_UL;
        var hole_DIV = '';
        var DIV_one = '';
        if (data[0].menuNm == "控制台") {
            DIV_one = '<div class="Home" id="consol"><a href="javascript:getIframeSrc("' + data[0].menuUrl + '")" id="Home" class="nav-header">' + data[0].menuNm + '</a></div>';
            i = 1;
        } else {
            i = 0;
        }
        for (i = i; i < data.length; i++) {
            DIV_before = '<div>';
            DIV_a = '<a href=' + data[i].menuUrl + ' class="nav-header togg" data-toggle="collapse"><span class="boxIcon glyphicon glyphicon-triangle-right"></span>' + data[i].menuNm + '</a>';
            DIV_ul_before = '<ul id=' + data[i].menuHtmlId + ' class="nav nav-list collapse">';
            var DIV_li = '';
            for (var j = 0; j < data[i].menuList.length; j++) {
                DIV_li += '<li class="boxLi"><a href=javascript:getIframeSrc("' + data[i].menuList[j].menuUrl + '") class="bClicked">' + data[i].menuList[j].menuNm + '</a></li>';
            }
            hole_UL = DIV_ul_before + DIV_li + '</ul>'; //ul
            hole_DIV += DIV_before + DIV_a + hole_UL + '</div>'; //div
        }
        Hole_DIV = DIV_one + hole_DIV;
        $('#sidebar-nav').append(Hole_DIV);
        DIV_one = '';
        $('#Name').text(localStorage.Lname);
        $('#Home').click(function () {
            getIframeSrc('waitIndex.html');
        })
        $('.togg').mouseup(function () {
            if ($(this).children().attr('class') == 'boxIcon glyphicon glyphicon-triangle-bottom') {
                $(this).children().attr('class', 'boxIcon glyphicon glyphicon-triangle-right');
            } else {
                $(this).children().attr('class', 'boxIcon glyphicon glyphicon-triangle-bottom');
            }
            if ($(this).next('ul').hasClass('in')) {
                $(this).children().attr('class', 'boxIcon glyphicon glyphicon-triangle-right');
            } else {
                $(this).children().attr('class', 'boxIcon glyphicon glyphicon-triangle-bottom');
            }
        })
        // 左侧分级导航
        $('.boxLi').click(function () {
            $('#consol').css('background-color', '#EBEBEB');
            $('.boxLi').css('background-color', '#EBEBEB');
            $('.boxLi').children().css('background-color', '#EBEBEB');
            $(this).css('background-color', '#ffffff');
            $(this).children().css('background-color', '#ffffff');
        })
        $('#consol').click(function () {
            $(this).css('background-color', '#ffffff');
            $('.boxLi').css('background-color', '#EBEBEB');
            $('.boxLi').children().css('background-color', '#EBEBEB');
        })
    }, function () {
        alert('获取数据失败')
    })
});
function getIframeSrc(_URL) { 
    document.getElementById("ifameView").src = _URL;
}
// 修改密码
$('#Reset').click(function () {
    var account = $('#Name').text();
    var oldPassw = $('#oldPassword').val();
    var newPassw = $('#newPassword').val();
    var newPassagain = $('#newPasswordAgain').val();
    if (newPassw != newPassagain) {
        alert('两次密码不一致！')
    } else {
        $ajax('post', 'http://' + window.location.host + '/wsyypt/SysUser/editPassWord', { 
                'password': oldPassw,
                'newPassword': newPassw,
                'account': account
            },
            'json',
            function (data) { //
                if (data == 1) {
                    alert('修改成功！')
                    $('#oldPassword').val('');
                    $('#newPassword').val('');
                    $('#newPasswordAgain').val('');
                    $('#resetPassword').modal('hide');
                } else {
                    alert('密码错误')
                }
            },
            function () {
                alert('操作失败，请稍后重试！')
            }
        )
    }
})
// 退出登录
$('#refreshPower').click(function () {
    document.cookie = '';
    delAllCookie();
    //删除cookie中所有定变量函数    
    function delAllCookie() {
        var myDate = new Date();
        myDate.setTime(-1000); //设置时间    
        var data = document.cookie;
        var dataArray = data.split("; ");
        for (var i = 0; i < dataArray.length; i++) {
            var varName = dataArray[i].split("=");
            document.cookie = varName[0] + "=''; expires=" + myDate.toGMTString();
        }
    }
    location.href = '../index-inner.html';
})